package com.example.activiti.config.redis;

import lombok.Data;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

@Data
@EnableConfigurationProperties(JedisProperties.class)
public class RedisPool {

    private JedisProperties properties;
    private JedisPoolConfig config;
    private JedisPool jedisPool;


    public RedisPool() {
        jedisPool = new JedisPool(config, properties.getHost(), properties.getPort(), properties.getTimeOut(), properties.getPassword());
    }

    public Jedis getResource() {
        return jedisPool.getResource();
    }

    public void releaseResource(Jedis jedis) {
        if (jedis != null){
            jedis.close();
        }
    }

}
